<template>
    <div>
        <div class="data-content">
            <div class="table-edit">
                <!--用户名-->
                <span>用户名</span>
                <Input v-model="username" placeholder="搜索" style="width:140px"/>

                <!--日期-->
                <DatePicker style="padding: 10px 0"
                            :open="open"
                            :value="search_date"
                            confirm
                            placement="bottom-end"
                            type="daterange"
                            @on-clear="dateClear"
                            @on-change="dateChange"
                            @on-ok="dateOk">
                    <a href="javascript:void(0)" class="c666" @click="dateClick">
                           <span>
                               <Icon type="calendar"></Icon>
                               <template><strong>{{ search_date_format }}</strong></template>
                           </span>
                    </a>
                </DatePicker>
                <Button type="info">查询</Button>
            </div>
            <Table :loading="loading" border :columns="columns" :data="user_list" class="no-border-table"
                   @on-selection-change="selectItem" ref="agent_deposit"></Table>

            <div>
                <Button @click="handleSelectAll(true)">全选</Button>
                <Button>反选</Button>
                <Button @click="handleSelectAll(true)">取消</Button>
                <Button type="primary" @click="del_model = !del_model">删除</Button>
            </div>
            <Page v-if="userCount > 0" :total="userCount" :current="page_num" @on-change="changePage"
                  @on-page-size-change="changePageSize" size="small" show-total show-sizer class="table-page">
                <slot class="total">共 {{ userCount }} 条</slot>
            </Page>
        </div>

        <Modal
                v-model="del_model"
                title="操作提示">
            <p>真的要删除当前选中项吗？一旦删除将无法恢复，请想好了再决定 </p>
            <div slot="footer">
                <Button type="text" @click="del_model = false">取消</Button>
                <Button type="error" :loading="send_loading" @click="delConfirm">删了</Button>
            </div>
        </Modal>
        <!--用户信息-->
        <UserMsgModal :usermsg_show="usermsg_show" :usermsg_loading="usermsg_loading" :usermsg="usermsg" @usermsgOk="usermsgOk"></UserMsgModal>

        <!--信息内容-->
        <Modal
                v-model="msg_show"
                title="会员信息"
                :loading="msg_loading"
                @on-ok="msgOk">
            <Form :model="msgdata" label-position="right" :label-width="100">
                <FormItem label="发送用户：">
                    <span v-html="msgdata.senduser"></span>
                </FormItem>
                <FormItem label="短信标题：">
                    <span v-html="msgdata.title"></span>
                </FormItem>
                <FormItem label="短信内容：">
                    <span v-html="msgdata.text"></span>
                </FormItem>
                <FormItem label="发送时间：">
                    <span v-html="msgdata.time"></span>
                </FormItem>
            </Form>

        </Modal>

        <transition name="router-slid">
            <router-view></router-view>
        </transition>

    </div>
</template>
<script>
    import WrapperContent from '../../../components/wrapper-content.vue'
    import {getUserList, getUser, getLevelList, getPositionList,doUserInfo,delUser,changeUserState} from "@/api/user";
    import * as utils from '../../../assets/js/utils'
    import $ from 'jquery'
    import _ from 'lodash'
    import UserMsgModal from  './../../common/userMsgModal.vue'

    export default {
        components: {
            WrapperContent,UserMsgModal
        },
        data() {
            return {
                username:'',//用户名
                search_date: [],
                open: false,
                statusList:[],
                status:'',
                self: this,
                level_list: [],
                position_list: [],
                del_model: false,
                select_users: [],
                send_loading: false,
                page_size: 10,
                page_num: 1,
                keyword: '',
                loading: true,
                columns: [
                    {
                        type: 'selection',
                        width: 60,
                        align: 'center'
                    },
                    {
                        type: 'selection',
                        title: '编号',
                    },
                    {
                        type: '发送用户',
                        title: '编号',
                    },
                    {
                        title: '接收用户',
                        key: 'tel',
                        align: 'center',
                        render: (h, params) => {
                            return h('Button', {
                                props: {
                                    type: 'text',
                                    size: 'small',
                                },
                                on: {
                                    click: () => {
                                        this.usermsg_show = true ;
                                    }
                                }
                            }, params.row.tel);
                        }
                    },
                    {
                        title: '时间',
                        key: 'login_ip',
                    },
                    {
                        title: '标题',
                        key: 'tel',
                        align: 'center',
                        render: (h, params) => {
                            return h('Button', {
                                props: {
                                    type: 'text',
                                    size: 'small',
                                },
                                on: {
                                    click: () => {
                                        this.usermsg_show = true ;
                                    }
                                }
                            }, params.row.title);
                        }
                    },
                    {
                        title: '操作',
                        key: 'action',
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: '',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '3px'
                                    },
                                    on: {
                                        click: () => {
                                            this.del_model();
                                        }
                                    }
                                }, '删除'),
                            ]);
                        }
                    }
                ],
                user_list: [{title:'jsfgsjdghfjfd'}],
                userCount: 0,
                usermsg_show:false,
                usermsg_loading : false ,
                usermsg:{
                    id:'13518298587',
                    name:'xx',
                    type:'正式',
                    tel:'13518298587',
                    cash_deposit:'200',
                    balance:'1',
                    register_time:'2018/11/12',
                    last_login_time:'01-22/10:11'
                },
                msg_show :false,
                msg_loading:false,
                msgdata:{
                    senduser:'8394568357',
                    title:'用户【13688155359】申请提款1000元！请及时处理！',
                    text:'申请提款信息如下：\n' +
                    '\n' +
                    '用户名：13688155359\n' +
                    '\n' +
                    '代 理 商：agent\n' +
                    '\n' +
                    '提款金额：1000元\n' +
                    '\n' +
                    '申请时间：2019-01-22 12:16:17',
                    time:'2019-01-22 12:16:17'
                }
            }
        },
        computed: {
            search_date_format: function () {
                if (this.search_date.length > 0) {
                    return this.search_date[0] + '~' + this.search_date[1];
                } else {
                    return '选择筛选日期'
                }
            }
        },
        created: function () {
            this.loading = false;
            this.userCount = 1 ;
            /* this.getUserList();
             this.getLevelList();
             this.getPositionList()*/
        },
        methods: {
            dateClick() {
                this.open = !this.open;
            },
            dateChange(date) {
                this.search_date = date;
            },
            dateOk() {
                this.page_num = 1;
                // this.getList();
                this.open = false;
            },
            dateClear() {
                this.search_date = [];
            },
            getUserList() {
                let app = this;
                getUserList(this.page_size, this.page_num, this.keyword).then(res => {
                    app.loading = false;
                    app.user_list = res.data.list;
                    app.userCount = Number(res.data.count)
                });
            },
            getInfo() {
                let app = this;
                getUser(app.formValidate.user_id).then(res => {
                    if (res.data) {
                        app.formValidate.user_id = res.data.id;
                        app.formValidate.account = res.data.account;
                        app.formValidate.realname = res.data.realname;
                        app.formValidate.level_id = res.data.level_id;
                        app.formValidate.position_id = res.data.position_id;
                        app.formValidate.state = res.data.state
                    }
                });
            },
            getLevelList() {
                let app = this;
                getLevelList(50).then(res => {
                    app.level_list = res.data.list
                });
            },
            getPositionList() {
                let app = this;
                getPositionList(50).then(res => {
                    app.position_list = res.data.list
                });
            },
            search: _.debounce(
                function () {
                    this.page_num = 1;
                    this.getUserList()
                },
                // 这是我们为用户停止输入等待的毫秒数
                500
            ),
            selectItem(selection) {
                let app = this;
                app.select_users = [];
                $.each(selection, function (k, v) {
                    app.select_users.push(v.id)
                });
            },
            changePage(page) {
                this.page_num = page;
                this.getUserList()
            },
            changePageSize(page_size) {
                this.page_num = 1;
                this.page_size = page_size;
                this.getUserList()
            },
            reloadList() {
                this.getUserList(1, this.page_size)
            },
            rowClassName(row, index) {
                return 'rowClassName';
            },
            changeState(id, state, index) {
                let app = this;
                const change_state = state == 1 ? 0 : 1;
                changeUserState(id,state == 1 ? 0 : 1).then(res => {
                    app.user_list[index].state = change_state
                });
            },
            toset(){

            },
            toback(){

            },
            handleSelectAll (status) {
                this.$refs.user_deposit.selectAll(status);
            },
            usermsgOk(){
                let app = this ;
                setTimeout(() => {
                    app.usermsg_show = false;
                }, 2000);
            },
            msgOk(){
                let app = this ;
                setTimeout(() => {
                    app.msg_show = false;
                }, 2000);
            },
            delConfirm(){
                let app = this ;
                setTimeout(() => {
                    app.del_model = false;
                }, 2000);
            }
        }
    }
</script>
